//Copyright (C) 2009 Ron Coleman. Contact: ronncoleman@gmail.com
//
//This library is free software; you can redistribute it and/or
//modify it under the terms of the GNU General Public License
//as published by the Free Software Foundation; either
//version 3 of the License, or (at your option) any later version.
//
//This library is distributed in the hope that it will be useful,
//but WITHOUT ANY WARRANTY; without even the implied warranty of
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
//General Public License for more details.
//
//You should have received a copy of the GNU General Public License
//along with this library; if not, write to the Free Software
//Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA

package org.workplicity.cia.model;

import java.util.ArrayList;
import java.util.List;
import org.workplicity.cia.util.WorkDate;

/**
 * This class represents a work request.
 * 
 * @author Ron Coleman
 * 
 */

public class LocalWorkRequest extends Entry {
    
	private static final long serialVersionUID = 5458915953363472975L;

	public enum Status {
        NA,
        OPEN,
        DISPATCHED,
        STARTED,
        HOLD,
        FINISHED,
        CLOSED,
        PENDING,
        RECURRING
    }
    
    protected Integer serviceId = -1;
    
    protected String descr = "";

    protected List<Comment> comments = new ArrayList<Comment>();

    protected Integer futureId = -1;

    protected Integer inventoryId = -1;

    protected List<Audit> trail = new ArrayList<Audit>( );

    protected WorkDate requestDate = new WorkDate(System.currentTimeMillis());
    protected WorkDate assignedDate = null;
    protected WorkDate completeDate = null;
    protected List<Integer> supplies = new ArrayList<Integer>( );

    /**
     * Constructor
     */
    public LocalWorkRequest() {
    }

    /**
     * Gets the comments for this work order.
     * @return Comments
     */
    public List<Comment> getComments() {
        return comments;
    }

    public void setComments(List<Comment> comments){
        this.comments = comments;
    }

    public String getDescr() {
        return descr;
    }

    public void setDescr(String description) {
        this.descr = description;
    }

    public Integer getServiceId() {
        return serviceId;
    }

    public void setServiceId(Integer serviceId) {
        this.serviceId = serviceId;
    }

    @Override
    public String toString() {
        return this.descr;
    }

    public void setFutureId(Integer recurId) {
        this.futureId = recurId;
    }

    /**
     * Get the value of completeDate
     *
     * @return the value of completeDate
     */
    public WorkDate getCompleteDate() {
        return completeDate;
    }

    /**
     * Set the value of completeDate
     *
     * @param completeDate new value of completeDate
     */
    public void setCompleteDate(WorkDate completeDate) {
        this.completeDate = completeDate;
    }


    /**
     * Get the value of assignedDate
     *
     * @return the value of assignedDate
     */
    public WorkDate getAssignedDate() {
        return assignedDate;
    }

    /**
     * Set the value of assignedDate
     *
     * @param assignedDate new value of assignedDate
     */
    public void setAssignedDate(WorkDate assignedDate) {
        this.assignedDate = assignedDate;
    }

    /**
     * Get the value of requestDate
     *
     * @return the value of requestDate
     */
    public WorkDate getRequestDate() {
        return requestDate;
    }

    /**
     * Set the value of requestDate
     *
     * @param requestDate new value of requestDate
     */
    public void setRequestDate(WorkDate requestDate) {
        this.requestDate = requestDate;
    }

    public void setStatus(Integer byId,Status status) {
        trail.add(new Audit(byId,status));
    }

    public void setStatus(Status status){
        setStatus(getUpdateUserId(),status);
    }

    public Status getStatus() {
        if(trail.isEmpty())
            return Status.NA;

        int sz = trail.size();

        return trail.get(sz-1).getStatus();
    }

    public List<Audit> getTrail() {
        return trail;
    }

    public Integer getInventoryId() {
        return inventoryId;
    }

    public void setInventoryId(Integer inventoryId) {
        this.inventoryId = inventoryId;
    }

    public Integer getFutureId() {
        return futureId;
    }

    public List<Integer> getSupplies() {
        return supplies;
    }

}
